using UnityEngine;
using UnityEngine.UI;

public class LevelIndexUI : MonoBehaviour
{
	[SerializeField]
	private ScrollRectSnapElement m_SnapWidget;

	[SerializeField]
	private Image[] m_Lights;

	[SerializeField]
	private Image m_LastLight;

	[SerializeField]
	private Image m_LeftArrow;

	[SerializeField]
	private Image m_RightArrow;

	[SerializeField]
	private float m_Time;

	private void Awake()
	{
		float time = m_Time;
		m_Time = 0f;
		SetLightOn(0);
		m_Time = time;
	}

	public void OnLeftArrowClick()
	{
		m_SnapWidget.Snap2Element(m_SnapWidget.currentIndex - 1);
	}

	public void OnRightArrowClick()
	{
		m_SnapWidget.Snap2Element(m_SnapWidget.currentIndex + 1);
	}

	public void SetLightOn(int index)
	{
		if (m_LastLight != null)
		{
			SetAlpha0(m_LastLight);
		}
		SetAlpha1(m_Lights[index]);
		m_LastLight = m_Lights[index];
		if (index > 0)
		{
			SetAlpha1(m_LeftArrow);
		}
		else
		{
			SetAlpha0(m_LeftArrow);
		}
		if (index < m_Lights.Length - 1)
		{
			SetAlpha1(m_RightArrow);
		}
		else
		{
			SetAlpha0(m_RightArrow);
		}
	}

	private void SetAlpha0(Image image)
	{
		iTween.FadeTo(image.gameObject, 0f, m_Time);
	}

	private void SetAlpha1(Image image)
	{
		iTween.FadeTo(image.gameObject, 1f, m_Time);
	}
}
